﻿using System;


class Program
{
    static void Main()
    {
        Console.Write("How long will be your array : ");
        int n = int.Parse(Console.ReadLine());
        int[] Array = new int[n];
        Console.WriteLine("Insert {0} integer", n);
        for (int i = 0; i < Array.Length; i++)
        {
            Console.Write("{0}:", i + 1);
            Array[i] = int.Parse(Console.ReadLine());
        }
        int Sum = new int();
        int NewSum = new int();
        int CurrentSum = new int();
        int FinalSum = int.MinValue;
        int StartIndex = 0;
        int IndexCheck = 0;
        int FinalIndex = 0;
        for (int i = 0; i < Array.Length-1; i++)
        {
            Sum = int.MinValue;
            NewSum = Array[i];
            for (int j = i+1; j < Array.Length; j++)
            {
                NewSum += Array[j];
                if (NewSum > Sum)
                {
                    CurrentSum = NewSum;
                    Sum = NewSum;
                    IndexCheck = j;
                }
            }
            if (FinalSum < CurrentSum)
            {
                FinalSum = CurrentSum;
                FinalIndex = IndexCheck;
                StartIndex = i;
            }
        }
        Console.WriteLine("Maximal sum = {0}" , FinalSum);
        Console.WriteLine("Integer that create Maximal sum have value : ");
        for (int s = StartIndex; s <= FinalIndex; s++)
        {
            Console.Write("{0} ", Array[s]);
        }
        Console.WriteLine();
    }
}
